package com.psbc.springbootstudydemo1.asynctask;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import java.util.concurrent.Future;

@Component
@Async
public class AsyncTask {
    public void task1() throws InterruptedException {
        System.out.println("task1执行");
        Thread.sleep(4000);
    }
    public void task2() throws InterruptedException {
        System.out.println("task2执行");
        Thread.sleep(4000);
    }
    public void task3() throws InterruptedException {
        System.out.println("task3执行");
        Thread.sleep(4000);
    }
    public Future<String> task4(){
        try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("task4执行");
        return new AsyncResult<String>("异步任务task4的返回结果");
    }
    public Future<String> task5(){
        try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("task5执行");
        return new AsyncResult<String>("异步任务task5的返回结果");
    }
}
